package com.qingke.easyjava.jdbc.command.impl;

import java.util.ArrayList;
import java.util.List;

import com.qingke.easyjava.jdbc.app.BeSuperDao;
import com.qingke.easyjava.jdbc.command.PlayerCommand;
import com.qingke.easyjava.jdbc.pojo.Player;
import com.qingke.easyjava.jdbc.pojo.Question;
import com.qingke.easyjava.jdbc.util.QingkeConsole;

public class ListCommand extends PlayerCommand{

	public ListCommand(Player playerProfile) {
		super(playerProfile);
	}

	@Override
	public void execute() {
		String mode = QingkeConsole.askUserInput("Please chooese the list mode:(ALL | MINE | OPEN | ID)");
		
		if(!"ALL|MINE|OPEN|ID".contains(mode.toUpperCase())) {
			QingkeConsole.println("Invalid mode!");
			return;
		}
		
		BeSuperDao dao = new BeSuperDao();
		List<Question> questions = new ArrayList<>();
		if("ALL".equalsIgnoreCase(mode)) {
			questions = dao.getQuestions();
		}else if("MINE".equalsIgnoreCase(mode)) {
			questions = dao.getQuestionFrom(playerProfile);
		}else if("OPEN".equalsIgnoreCase(mode)) {
			List<Question> tempList = dao.getQuestions();
			for(Question question : tempList) {
				questions.add(question);
			}
		}else if("ID".equalsIgnoreCase(mode)) {
			long id = QingkeConsole.askUserInputInt("Please enter question ID:");
			
			Question question = dao.getQuestion(id);
			questions.add(question);
		}
		
		for(Question question : questions) {
			QingkeConsole.println(question);
		}
	}

}
